//
//  LSZLeftViewController.m
//  Heart Fire
//
//  Created by mac on 15/12/26.
//  Copyright © 2015年 TUcheng. All rights reserved.
//

#import "YYT_LeftViewController.h"
#import "YYT_DrawerViewController.h"
#import "AppDelegate.h"
#import "UIImageView+WebCache.h"
#import "YYT_LeftView.h"
#import <BmobSDK/Bmob.h>
#import "YYT_LoginViewController.h"
#import "YYT_RegisterViewController.h"
#import "YYT_ChannelViewController.h"
#import "YYT_TheOffcialViewController.h"
#import "YYT_HIstoryViewController.h"
#import "YYT_DataBaseSingleton.h"
#import "YYT_DownloadViewController.h"
#import "YYT_YuedanLeftViewController.h"
@interface LSZLeftViewController ()
<
    YYT_LeftViewDelegate
>
@property (nonatomic, strong)YYT_LeftView *leftView;

@end

@implementation LSZLeftViewController

-(void)viewWillAppear:(BOOL)animated{
    BmobUser *bUser = [BmobUser getCurrentUser];
    if (bUser) {
        [self.leftView.myTableView reloadData];
    }else{
        //对象为空时，可打开用户注册界面
        [self.leftView.myTableView reloadData];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.leftView = [[YYT_LeftView alloc] initWithFrame:self.view.bounds];
    _leftView.backgroundColor = BLACK_COLOR;
    [self.view addSubview:_leftView];
    _leftView.delegate = self;

}

- (void)xiazai{
    YYT_DownloadViewController *down = [[YYT_DownloadViewController alloc]init];
    UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:down];
    [self presentViewController:na animated:YES completion:^{
        
        
    }];
}

//注册框弹起
-(void)regisPopView{
    YYT_RegisterViewController
    *regis = [[YYT_RegisterViewController alloc] init];
    UINavigationController *regisNa = [[UINavigationController alloc] initWithRootViewController:regis];
    [self presentViewController:regisNa animated:YES completion:nil];
}
//登录框弹起
- (void)loginPopView{
    YYT_LoginViewController *login = [[YYT_LoginViewController alloc] init];
    UINavigationController *loginNa = [[UINavigationController alloc] initWithRootViewController:login];
    [self presentViewController:loginNa animated:YES completion:nil];
}
- (void)logOut{
    [BmobUser logout];
    [self.leftView.myTableView reloadData];
    NSLog(@"注销成功");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pindao{
    YYT_ChannelViewController *pindao = [[YYT_ChannelViewController alloc]init];
    UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:pindao];
    [self presentViewController:na animated:YES completion:^{
        
        
    }];
}

//悦单
- (void)yuedan{
    YYT_YuedanLeftViewController *yuedanLVC = [[YYT_YuedanLeftViewController alloc]init];
    UINavigationController *yuedanNavc = [[UINavigationController alloc]initWithRootViewController:yuedanLVC];
    [self presentViewController:yuedanNavc animated:YES completion:^{
        
        
    }];
}
- (void)qingchu{
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"清除缓存后会重新加载数据,\n如果是在流量状态下会消耗您的流量\n是否继续!" preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alertC animated:YES completion:^{
        
        
        
    }];
    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        //清除缓存
        [[SDImageCache sharedImageCache]clearDisk];
        
        
        UIAlertController *alertE = [UIAlertController alertControllerWithTitle:@"提示" message:@"已成功清除你的缓存" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertE animated:YES completion:^{
            
            
            
        }];
        
        UIAlertAction *alertD = [UIAlertAction actionWithTitle:@"我知道了!" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            
            [self.leftView.myTableView reloadData];
            
        }];
        [alertE addAction:alertD];
        
        
    }];
    [alertC addAction:alertA];
    
    UIAlertAction *alertB = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        
        
    }];
    [alertC addAction:alertB];
}
//首页
- (void)TheOfficial{
    AppDelegate *appdelegate = [[UIApplication sharedApplication]delegate];
    YYT_DrawerViewController *drawerVC = [appdelegate drawerViewController];
    [drawerVC hideSideViewController:YES];
}
- (void)history{
    YYT_HIstoryViewController *history = [[YYT_HIstoryViewController alloc] init];
    NSArray *array = [[YYT_DataBaseSingleton shareDataBase]chaxunseebiao];
    
    if (array.count == 0) {
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有播放记录" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *act = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
    
}];
        [alertC addAction:act];
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];
    }else{
    UINavigationController *historyVC = [[UINavigationController alloc] initWithRootViewController:history];
    [self presentViewController:historyVC animated:YES completion:^{
        
       
        
        
    }];

}
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
